package au.org.htd.youslide;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.api.datastore.Blob;
import com.google.appengine.api.datastore.Key;

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Attachment {
	public static final String AUDIO = "mp3wmaogg";
	public static final String PDF = "pdf";
	public static final String DOC = "docx";
	public static final String PICTURE = "jpgjpegpnggif";

	public static final String[] TYPES = { AUDIO, PDF, DOC, PICTURE };

	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Key id;

	@Persistent
	private Blob data;

	@Persistent
	private String name;

	public Attachment(String name, Blob data) {
		this.name = name;
		this.data = data;
		for (String type : TYPES) {
			if (type.indexOf(name) > -1) {
				this.attachmentType = type;
			}
		}
	}

	public String getName() {
		return name;
	}

	public Blob getData() {
		return data;
	}

	public void setData(Blob data) {
		this.data = data;
	}

	public void setData(byte[] data) {
		this.data = new Blob(data);
	}

	public Key getId() {
		return id;
	}

	@Persistent
	private String attachmentType;

	public String getAttachmentType() {
		return attachmentType;
	}

	public void setAttachmentType(String attachmentType) {
		this.attachmentType = attachmentType;
	}
}
